--
-- Author: mm
-- Date: 2018-04-17 15:06:49
--
-- HandbookRender
--

local ClassRef = app.mvc.createListViewCell(...)

local maxStrNum = 5 -- 星级最大数量
local HandbookHelper = require("app.handBook.HandbookHelper")
--data =
function ClassRef.create()
    local sprite = ClassRef.extend(cc.CSLoader:createNode(Res.HandBookRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end


--
function ClassRef:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui["Panel"]:getContentSize())
    self._ui["Panel/Panel_bom/Panel_star"]:setSwallowTouches( false )
    self._ui["Panel/Panel_bom/Panel_star/btn_go"]:setSwallowTouches( false )
    display.uiAddClick( self._ui["Panel"], function(sender, eventType)
        -- executeFunc(self._onClick, self)
        if self._cellModel then
            self._cellModel:dispatchEvent("click", self._data)
        end
    end, true, 0.02)
    self:refresh()
end

-- data = directory_listConf
function ClassRef:refresh()
    if self._data then
        
        local data = self._data
        local config = data.config
        local iconPath = GD:getImagePath( Res.directoryBgPath, config.cardIcon )
        self._ui.img:loadTexture( iconPath )

        self._ui.tlt:setString( L(config.name) )
        self._ui.text:setString( L(config.desc) )

        local rewardIconPath = GD:getImagePath( Res.coinIconPath, config.rewardIcon )
        self._ui.icon:loadTexture( rewardIconPath )

        local rewardLv = tonumber( config.star  or 0 )
        for i = 1, maxStrNum do
            self._ui[ "Panel/Panel_bom/Panel_star/s" .. i ]:setVisible( i <= rewardLv )
        end

        if config.tips and "" ~= config.tips then -- 存在进度概念？
            self._ui.num:setVisible( true )
           
            local curV = data.curNum
            if curV == nil then
                self._ui.num:setVisible( false )
            elseif curV < 0 then
                self._ui.num:setString(L("done"))
            else
                self._ui.num:setString(L(config.tips):format(tostring(curV)))
            end
        else
            self._ui.num:setVisible( false )
        end
    end
end



return ClassRef
